/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#include <iostream>
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "stub.h"
#include "ApplicationProtectPlugin_types.h"
#include "ApplicationProtectBaseDataType_types.h"
#include "backup/ReplicationBackupJob.h"
#include "ClientInvoke.h"
#include "PluginUtilities.h"
#include "device_access/ControlDevice.h"
#include "nas_share/common/HetroCommonService.h"

using ::testing::_;
using testing::AllOf;
using ::testing::AnyNumber;
using ::testing::AtLeast;
using testing::ByMove;
using testing::DoAll;
using ::testing::Eq;
using ::testing::Field;
using ::testing::Ge;
using ::testing::Gt;
using testing::InitGoogleMock;
using ::testing::Invoke;
using ::testing::Ne;
using ::testing::Return;
using ::testing::Sequence;
using ::testing::SetArgReferee;
using ::testing::SetArgumentPointee;
using ::testing::Throw;
using namespace NasRepServiceObjOp;
using namespace AppProtect;
using namespace std;
using namespace Module;

class ReplicationBackupJobTest : public testing::Test {
public:
    void SetUp();
    void TearDown();
    static void SetUpTestCase() {}
    static void TearDownTestCase() {}
    Stub stub;
    std::shared_ptr<DoradoNas> m_localController;
    std::shared_ptr<DoradoNas> m_remoteController;

    std::unique_ptr<ReplicationBackupJob> m_nasReplicationBackupJob;
};

static AppProtect::BackupJob BackupJobSetup()
{
    BackupJob homoBackupJob;
    
    homoBackupJob.jobId = "main_job_id_000";
    homoBackupJob.requestId = "000001";
    homoBackupJob.protectEnv.__isset.auth = true;
    homoBackupJob.protectEnv.auth.__set_authkey("admin");
    homoBackupJob.protectEnv.auth.__set_authPwd("Admin@123");
    homoBackupJob.protectEnv.__set_endpoint("8.40.102.115");
    homoBackupJob.protectEnv.__set_port(8088);
    homoBackupJob.protectEnv.extendInfo = "{\"snapConsistency\":\"0\",\"verifyStatus\":\"1\",\"wwn\":\"\"}";
    homoBackupJob.protectEnv.auth.extendInfo = "{\"fingerPrint\" : \"4928EBB6E58A3A395BC89317DD55B82F1B8C10E7\"}";

    homoBackupJob.protectObject.__set_id("147");
    homoBackupJob.protectObject.__set_name("test_123456");
    homoBackupJob.protectObject.__set_extendInfo("{\"tenantName\":\"d0\", \"fileSystemId\":\"148\", \"usedCapacity\":\"5986\", \"onlineStatus\":\"1\", \"tenantId\":\"15\", \"capacity\":\"123456789\"}");
    
    StorageRepository storage;
    storage.__isset.auth = true;
    storage.__isset.endpoint = true;

    storage.repositoryType = RepositoryDataType::type::DATA_REPOSITORY;
    storage.auth.__set_authkey("admin");
    storage.auth.__set_authPwd("Admin@123");
    storage.endpoint.ip = "8.40.102.105,8.40.102.106";
    storage.endpoint.port = 8088;
    storage.__set_remotePath("/Storage_1234/123456789");

    StorageRepository storage2;
    storage2.__isset.auth = true;
    storage2.__isset.endpoint = true;

    storage2.repositoryType = RepositoryDataType::type::META_REPOSITORY;
    storage2.auth.__set_authkey("admin");
    storage2.auth.__set_authPwd("Admin@123");
    storage2.endpoint.ip = "8.40.102.105,8.40.102.106";
    storage2.endpoint.port = 8088;
    storage2.__set_remotePath("/Storage_1234/123456789");
    vector<string> path {"/home"};
    storage2.__set_path(path);

    homoBackupJob.repositories.push_back(storage);
    homoBackupJob.repositories.push_back(storage2);

    return homoBackupJob;
}

static void returnVoid_Stub(void *obj, ActionResult& returnValue, const SubJobDetails& jobInfo)
{
    return;
}

void ReplicationBackupJobTest::SetUp()
{
    m_nasReplicationBackupJob = std::make_unique<ReplicationBackupJob>();

    SubJob subJob;
    // subJobId keyword is optional, this operation is necessary
    subJob.__isset.subJobId = true;
    subJob.__set_jobId("sub_job_id");
    subJob.jobId = "jobId123";
    subJob.subJobId = "subJob123";
    subJob.jobName = "XYZ";
    subJob.jobPriority = 1;
    subJob.jobInfo = "{\"ControlFile\":\"\",\"SubTaskType\":1,\"Ext\":\"\"}";

    // test BackupPrerequisiteJob
    AppProtect::BackupJob homoBackupJob = BackupJobSetup();
    auto jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(homoBackupJob));
    m_nasReplicationBackupJob->SetJobInfo(jobInfo);
    m_nasReplicationBackupJob->m_backupPara = make_shared<BackupJob>(homoBackupJob);
    std::shared_ptr<SubJob> subJobptr = std::make_shared<SubJob>(subJob);
    m_nasReplicationBackupJob->SetSubJob(subJobptr);

    ControlDeviceInfo basicDeviceInfo;
    basicDeviceInfo.deviceName = "test";  // 文件系统名称在pair预处理过程中或者新创pair时会设置，此处不需要
    basicDeviceInfo.url = "";   // 使用安全IP登录，不需要IP和端口号
    basicDeviceInfo.port = "";  // 使用安全IP登录，不需要IP和端口号
    basicDeviceInfo.userName = "admin";
    basicDeviceInfo.password = "Huawei@123";
    basicDeviceInfo.poolId = 0;
    basicDeviceInfo.compress = false;
    basicDeviceInfo.dedup = false;
    basicDeviceInfo.poolId = 0;
    std::string m_productFSID = "1";
    m_localController = std::make_unique<DoradoNas>(basicDeviceInfo, false);
    m_remoteController = std::make_unique<DoradoNas>(basicDeviceInfo, m_productFSID, false);
    m_nasReplicationBackupJob->m_localDeviceController = std::make_unique<DoradoNas>(basicDeviceInfo, m_productFSID, false);
    m_nasReplicationBackupJob->m_remoteDeviceController = std::make_unique<DoradoNas>(basicDeviceInfo, m_productFSID, false);
    stub.set(sleep, returnVoid_Stub);
}

void ReplicationBackupJobTest::TearDown()
{
}

static void ReportJobDetailsSuc(void *obj, ActionResult& returnValue, const SubJobDetails& jobInfo)
{
    std::cout << "ReportJobDetailsSuc get called" << std::endl;
    return;
}

static void AddNewJobSuc(void *obj, ActionResult& returnValue, const std::vector<SubJob>& job)
{
    return;
}

bool CheckDeviceNetworkConnect_Stub_True(void *obj, std::string& managerIps)
{
    return true;
}

bool CheckDeviceNetworkConnect_Stub_False(void *obj, std::string& managerIps)
{
    return false;
}

bool InitDeviceInfo_Stub_True(void *obj) {
    return true;
}

bool InitDeviceInfo_Stub_False(void *obj) {
    return false;
}

static bool ReportCopyAdditionalInfo_Stub_True(void *obj, ActionResult& returnValue, const std::string& jobId, const Copy& copy)
{
    returnValue.code = MP_SUCCESS;
    return true;
}

static bool ReportCopyAdditionalInfo_Stub_False(void *obj, ActionResult& returnValue, const std::string& jobId, const Copy& copy)
{
    INFOLOG("ReportCopyAdditionalInfo_Stub_False get called");
    returnValue.code = MP_FAILED;
    return true;
}

static void ReportJobDetails_Stub(void *ob, ActionResult &returnValue, const SubJobDetails &jobInfo)
{
    return;
}

static void CleanTask_Stub_Void(void *obj, AppProtect::JobResult::type status)
{
    return;
}

static void CheckCertThumbPrint_Stub_True(void *obj, ActionResult& returnValue, const std::string& ip, const int32_t port, const std::string& thumbPrint)
{
    returnValue.code = MP_SUCCESS;
    return;
}

static bool UpdateDeviceAvilableIP_Stub_True(void *obj, ControlDeviceInfo &deviceInfo,
    const std::vector<std::string> &mgrIpList)
{
    return true;
}

static int QueryFileSystem_Stub_Virtual_True(void *obj, DeviceDetails &info)
{
    return 0;
}

static int QueryFileSystem_Stub_True(void *obj, std::string fileName, DeviceDetails &info)
{
    return 0;
}

static bool GetJobInfoBody_Stub_True(void *obj)
{
    return true;
}

static bool RemoveCertification_Stub_True(void *obj, const ApplicationEnvironment& protectEnv)
{
    std::cout << "RemoveCertification_Stub_True get called" << std::endl;
    return true;
}

static bool RemoveCertification_Stub_False(void *obj, const ApplicationEnvironment& protectEnv)
{
    std::cout << "RemoveCertification_Stub_False get called" << std::endl;
    return false;
}

static int IsExistPairValid_Stub_True(void *obj)
{
    return true;
}

static int IsExistPairValid_Stub_False(void *obj)
{
    return false;
}

static int GetPairInfoInProduct_Stub_True(void *obj, std::shared_ptr<DoradoNas>& productController,
    std::shared_ptr<DoradoNas>& basicController, std::string& pairID)
{
    return true;
}

static int GetPairInfoInProduct_Stub_False(void *obj, std::shared_ptr<DoradoNas>& productController,
    std::shared_ptr<DoradoNas>& basicController, std::string& pairID)
{
    return false;
}

static bool GetPairInfoByID_Stub_True(void *obj, std::shared_ptr<DoradoNas>& deviceController, const std::string& pairID,
    ReplicationPairInfo& replicationPairInfo)
{
    return true;
}

static bool GetPairInfoByID_Stub_False(void *obj, std::shared_ptr<DoradoNas>& deviceController, const std::string& pairID,
    ReplicationPairInfo& replicationPairInfo)
{
    return false;
}

static bool CreateReplicationPair_Stub_True(void *obj, std::shared_ptr<DoradoNas>& deviceController,
    const int& localResId, const std::string& remoteDevId, int& remoteResId, std::string &pairID)
{
    return true;
}

static bool CreateReplicationPair_Stub_False(void *obj, std::shared_ptr<DoradoNas>& deviceController,
    const int& localResId, const std::string& remoteDevId, int& remoteResId, std::string &pairID)
{
    return false;
}

static bool IsReportAgentErrorCode_Stub_True(void *obj, LogDetail logDetail)
{
    return true;
}

static bool IsReportAgentErrorCode_Stub_False(void *obj, LogDetail logDetail)
{
    return false;
}

static int GetErrorCode_Stub(void *obj, LogDetail logDetail)
{
    return 0;
}

static int Query_Stub_Suc(void *obj, DeviceDetails &info)
{
    return Module::SUCCESS;
}

static int Query_Stub_Fail(void *obj, DeviceDetails &info)
{
    return Module::FAILED;
}

static bool CreateSnapShotInStorage_Stub_True_1(void* obj)
{
    return true;
}

static bool CreateSnapShotInStorage_Stub_False_1(void* obj)
{
    return false;
}

static int GetESN_Stub_Suc(void* obj)
{
    return Module::SUCCESS;
}

static int GetESN_Stub_Fail(void* obj)
{
    return Module::FAILED;
}

static bool SplitReplicationPair_Stub_True(void *obj, std::shared_ptr<DoradoNas>& deviceController,
    const std::string& pairID)
{
    return true;
}

static bool SplitReplicationPair_Stub_False(void *obj, std::shared_ptr<DoradoNas>& deviceController,
    const std::string& pairID)
{
    return false;
}

static bool CreateSnapShotInStorage_Stub_True_2(void *obj, std::shared_ptr<DoradoNas>& deviceController,
    const std::string& snapshotname, std::string& snapshotID)
{
    return true;
}

static bool CreateSnapShotInStorage_Stub_False_2(void *obj, std::shared_ptr<DoradoNas>& deviceController,
    const std::string& snapshotname, std::string& snapshotID)
{
    return false;
}

static bool SwitchOverPrimaryAndSecondResource_Stub_False(void *obj, std::shared_ptr<DoradoNas>& deviceController,
    const std::string& pairID)
{
    return false;
}

static bool DeleteSnapShotInStorage_Stub_True(void *obj, std::shared_ptr<DoradoNas>& deviceController,
    const std::string& snapshotName)
{
    return true;
}

static bool DeleteSnapShotInStorage_Stub_False(void *obj, std::shared_ptr<DoradoNas>& deviceController,
    const std::string& snapshotName)
{
    return false;
}

/*
 * 用例名称:检查生成子任务
 * 前置条件：无
 * check点：生成子任务流程顺利运行
 */
TEST_F(ReplicationBackupJobTest, CheckGenerateSubJobSuc)
{
    typedef int (*fptr)(JobService*);

    fptr JobService_AddNewJob = (fptr)(&JobService::AddNewJob);
    stub.set(JobService_AddNewJob, AddNewJobSuc);

    fptr JobService_ReportJobDetails = (fptr)(&JobService::ReportJobDetails);
    stub.set(JobService_ReportJobDetails, ReportJobDetailsSuc);

    EXPECT_EQ(m_nasReplicationBackupJob->GenerateSubJob(), MP_SUCCESS);
    stub.reset(JobService_AddNewJob);
    stub.reset(JobService_ReportJobDetails);
}

/*
 * 用例名称：CheckAllowBackupInLocalNode
 * 前置条件：无
 * check点：AllowBackupInLocalNode无异常
 */
TEST_F(ReplicationBackupJobTest, CheckAllowBackupInLocalNode)
{
    stub.set(PluginUtils::CheckDeviceNetworkConnect, CheckDeviceNetworkConnect_Stub_True);
    EXPECT_NO_THROW(m_nasReplicationBackupJob->AllowBackupInLocalNode());
    stub.reset(PluginUtils::CheckDeviceNetworkConnect);
}

/*
 * 用例名称：CheckAllowBackupInLocalNode
 * 前置条件：无
 * check点：AllowBackupInLocalNode无异常
 */
TEST_F(ReplicationBackupJobTest, CheckAllowBackupInLocalNodeNoGet)
{
    stub.set(ADDR(ReplicationBackupJob, GetJobInfoBody), GetJobInfoBody_Stub_True);
    stub.set(PluginUtils::CheckDeviceNetworkConnect, CheckDeviceNetworkConnect_Stub_True);
    EXPECT_NO_THROW(m_nasReplicationBackupJob->AllowBackupInLocalNode());
    stub.reset(ADDR(ReplicationBackupJob, GetJobInfoBody));
    stub.reset(PluginUtils::CheckDeviceNetworkConnect);
}

/*
 * 用例名称：CheckAllowBackupInLocalNode
 * 前置条件：无
 * check点：AllowBackupInLocalNode无异常
 */
TEST_F(ReplicationBackupJobTest, CheckAllowBackupInLocalNodeNoConnect)
{
    stub.set(PluginUtils::CheckDeviceNetworkConnect, CheckDeviceNetworkConnect_Stub_False);
    EXPECT_NO_THROW(m_nasReplicationBackupJob->AllowBackupInLocalNode());
    stub.reset(PluginUtils::CheckDeviceNetworkConnect);
}

/*
 * 用例名称：检查后置任务
 * 前置条件：无
 * check点：后置任务流程顺利运行
 */
TEST_F(ReplicationBackupJobTest, CheckPostJobInner)
{
    typedef bool (*fptr)(ReplicationBackupJob*);
    typedef void (*fptr2)(ReplicationBackupJob*, AppProtect::JobResult::type);
    typedef mp_int32 (*fptr3)(JobService*);
    typedef bool (*fptr4)(ReplicationBackupJob*, const AppProtect::ApplicationEnvironment&);

    fptr ReplicationBackupJob_InitDeviceInfo = (fptr)(&ReplicationBackupJob::InitDeviceInfo);
    fptr2 ReplicationBackupJob_CleanTask = (fptr2)(&ReplicationBackupJob::CleanTask);
    fptr3 JobService_ReportJobDetails = (fptr3)(&JobService::ReportJobDetails);
    fptr4 ReplicationBackupJob_RemoveCertification = (fptr4)(&ReplicationBackupJob::RemoveCertification);

    stub.set(ReplicationBackupJob_InitDeviceInfo, InitDeviceInfo_Stub_True);
    stub.set(ADDR(JobService, ReportCopyAdditionalInfo), ReportCopyAdditionalInfo_Stub_True);
    stub.set(ReplicationBackupJob_CleanTask, CleanTask_Stub_Void);
    stub.set(JobService_ReportJobDetails, ReportJobDetailsSuc);
    stub.set(ReplicationBackupJob_RemoveCertification, RemoveCertification_Stub_True);
    m_nasReplicationBackupJob->SetPostJobResultType(AppProtect::JobResult::type::SUCCESS);
    EXPECT_EQ(m_nasReplicationBackupJob->PostJobInner(), MP_SUCCESS);
    stub.reset(ReplicationBackupJob_InitDeviceInfo);
    stub.reset(ADDR(JobService, ReportCopyAdditionalInfo));
    stub.reset(ReplicationBackupJob_CleanTask);
    stub.reset(JobService_ReportJobDetails);
    stub.reset(ReplicationBackupJob_RemoveCertification);
}

/*
 * 用例名称：检查后置任务
 * 前置条件：无
 * check点：后置任务流程运行失败
 */
TEST_F(ReplicationBackupJobTest, CheckPostJobInnerNoInitIsReport)
{
    typedef bool (*fptr)(ReplicationBackupJob*);
    typedef void (*fptr2)(ReplicationBackupJob*, AppProtect::JobResult::type);
    typedef mp_int32 (*fptr3)(JobService*);

    fptr ReplicationBackupJob_InitDeviceInfo = (fptr)(&ReplicationBackupJob::InitDeviceInfo);
    fptr2 ReplicationBackupJob_CleanTask = (fptr2)(&ReplicationBackupJob::CleanTask);
    fptr3 JobService_ReportJobDetails = (fptr3)(&JobService::ReportJobDetails);

    stub.set(ReplicationBackupJob_InitDeviceInfo, InitDeviceInfo_Stub_False);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_True);
    stub.set(JobService_ReportJobDetails, ReportJobDetailsSuc);
    EXPECT_EQ(m_nasReplicationBackupJob->PostJobInner(), MP_FAILED);
    stub.reset(ReplicationBackupJob_InitDeviceInfo);
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
    stub.reset(JobService_ReportJobDetails);
}

/*
 * 用例名称：检查后置任务
 * 前置条件：无
 * check点：后置任务流程运行失败
 */
TEST_F(ReplicationBackupJobTest, CheckPostJobInnerNoInit)
{
    typedef bool (*fptr)(ReplicationBackupJob*);
    typedef void (*fptr2)(ReplicationBackupJob*, AppProtect::JobResult::type);
    typedef mp_int32 (*fptr3)(JobService*);

    fptr ReplicationBackupJob_InitDeviceInfo = (fptr)(&ReplicationBackupJob::InitDeviceInfo);
    fptr2 ReplicationBackupJob_CleanTask = (fptr2)(&ReplicationBackupJob::CleanTask);
    fptr3 JobService_ReportJobDetails = (fptr3)(&JobService::ReportJobDetails);

    stub.set(ReplicationBackupJob_InitDeviceInfo, InitDeviceInfo_Stub_False);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_False);
    stub.set(JobService_ReportJobDetails, ReportJobDetailsSuc);
    EXPECT_EQ(m_nasReplicationBackupJob->PostJobInner(), MP_FAILED);
    stub.reset(ReplicationBackupJob_InitDeviceInfo);
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
    stub.reset(JobService_ReportJobDetails);
}

/*
 * 用例名称：检查后置任务
 * 前置条件：无
 * check点：后置任务流程顺利运行
 */
// TEST_F(ReplicationBackupJobTest, CheckPostJobInner2)
// {
//     typedef bool (*fptr)(ReplicationBackupJob*);
//     typedef void (*fptr2)(ReplicationBackupJob*, AppProtect::JobResult::type);
//     typedef mp_int32 (*fptr3)(JobService*);
//     typedef bool (*fptr4)(ReplicationBackupJob*, const AppProtect::ApplicationEnvironment&);

//     fptr ReplicationBackupJob_InitDeviceInfo = (fptr)(&ReplicationBackupJob::InitDeviceInfo);
//     fptr2 ReplicationBackupJob_CleanTask = (fptr2)(&ReplicationBackupJob::CleanTask);
//     fptr3 JobService_ReportJobDetails = (fptr3)(&JobService::ReportJobDetails);
//     fptr4 ReplicationBackupJob_RemoveCertification = (fptr4)(&ReplicationBackupJob::RemoveCertification);

//     stub.set(ReplicationBackupJob_InitDeviceInfo, InitDeviceInfo_Stub_True);
//     stub.set(ADDR(JobService, ReportCopyAdditionalInfo), ReportCopyAdditionalInfo_Stub_False);
//     stub.set(ReplicationBackupJob_CleanTask, CleanTask_Stub_Void);
//     stub.set(ADDR(JobService, ReportJobDetails), ReportJobDetails_Stub);
//     stub.set(ReplicationBackupJob_RemoveCertification, RemoveCertification_Stub_True);
//     m_nasReplicationBackupJob->SetPostJobResultType(AppProtect::JobResult::type::SUCCESS);
//     EXPECT_EQ(m_nasReplicationBackupJob->PostJobInner(), MP_SUCCESS);
//     stub.reset(ReplicationBackupJob_InitDeviceInfo);
//     stub.reset(ADDR(JobService, ReportCopyAdditionalInfo));
//     stub.reset(ReplicationBackupJob_CleanTask);
//     stub.reset(ADDR(JobService, ReportJobDetails));
//     stub.reset(ReplicationBackupJob_RemoveCertification);
// }

/*
 * 用例名称：检查后置任务
 * 前置条件：无
 * check点：后置任务流程失败
 */
TEST_F(ReplicationBackupJobTest, CheckPostJobInnerNoRemove)
{
    typedef bool (*fptr)(ReplicationBackupJob*);
    typedef void (*fptr2)(ReplicationBackupJob*, AppProtect::JobResult::type);
    typedef mp_int32 (*fptr3)(JobService*);
    typedef bool (*fptr4)(ReplicationBackupJob*, const AppProtect::ApplicationEnvironment&);

    fptr ReplicationBackupJob_InitDeviceInfo = (fptr)(&ReplicationBackupJob::InitDeviceInfo);
    fptr2 ReplicationBackupJob_CleanTask = (fptr2)(&ReplicationBackupJob::CleanTask);
    fptr3 JobService_ReportJobDetails = (fptr3)(&JobService::ReportJobDetails);
    fptr4 ReplicationBackupJob_RemoveCertification = (fptr4)(&ReplicationBackupJob::RemoveCertification);

    stub.set(ReplicationBackupJob_InitDeviceInfo, InitDeviceInfo_Stub_True);
    stub.set(ADDR(JobService, ReportCopyAdditionalInfo), ReportCopyAdditionalInfo_Stub_True);
    stub.set(ReplicationBackupJob_CleanTask, CleanTask_Stub_Void);
    stub.set(JobService_ReportJobDetails, ReportJobDetailsSuc);
    stub.set(ReplicationBackupJob_RemoveCertification, RemoveCertification_Stub_False);
    m_nasReplicationBackupJob->SetPostJobResultType(AppProtect::JobResult::type::SUCCESS);
    EXPECT_EQ(m_nasReplicationBackupJob->PostJobInner(), MP_FAILED);
    stub.reset(ReplicationBackupJob_InitDeviceInfo);
    stub.reset(ADDR(JobService, ReportCopyAdditionalInfo));
    stub.reset(ReplicationBackupJob_CleanTask);
    stub.reset(JobService_ReportJobDetails);
    stub.reset(ReplicationBackupJob_RemoveCertification);
}

/*
 * 用例名称：CheckCheckBackupJobType
 * 前置条件：无
 * check点：CheckBackupJobType执行成功
 */
TEST_F(ReplicationBackupJobTest, CheckCheckBackupJobType)
{
    EXPECT_EQ(m_nasReplicationBackupJob->CheckBackupJobType(), MP_SUCCESS);
}

/*
 * 用例名称:从jsonstring中获取双控ip
 * 前置条件：无
 * check点：获取ip争取
 */
TEST_F(ReplicationBackupJobTest, CheckGetMgrIp)
{
    std::string ext = "{\"managerIps\" : \"[\\\"8.40.97.165\\\", \\\"8.40.97.166\\\"]\", \"test\" : \"123\"}";

    INFOLOG("ext: %s", ext.c_str());
    std::vector<std::string> output;

    bool ret = m_nasReplicationBackupJob->GetMgrIpFromExt(output, ext);
    EXPECT_EQ(ret, true);
    EXPECT_EQ(output[0], "8.40.97.165");
    EXPECT_EQ(output[1], "8.40.97.166");
    EXPECT_EQ(m_nasReplicationBackupJob->m_productManageIps, "8.40.97.165,8.40.97.166");
}

static bool CreateResourceMock()
{
    return true;
}

static bool QueryResourceMock(
    const std::string key, AppProtect::ResourceStatus &ret, const std::string &mainJobId, const std::string &subJobId)
{
    AppProtect::Resource resource;
    resource.__set_resourceValue("1");
    ret.resource = resource;
    return true;
}

/*
 * 用例名称：CheckPreStartTask
 * 前置条件：无
 * check点：PreStartTask执行成功
 */
TEST_F(ReplicationBackupJobTest, CheckPreStartTask)
{
    typedef bool (*fptr)(ReplicationBackupJob*);

    fptr ReplicationBackupJob_InitDeviceInfo = (fptr)(&ReplicationBackupJob::InitDeviceInfo);

    stub.set((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem), QueryFileSystem_Stub_True);
    stub.set(ReplicationBackupJob_InitDeviceInfo, InitDeviceInfo_Stub_True);
    stub.set(ADDR(NasReplicationService, GetPairInfoInProduct), GetPairInfoInProduct_Stub_True);
    stub.set(ADDR(PluginUtils,CheckDeviceNetworkConnect), CheckDeviceNetworkConnect_Stub_True);
    stub.set(ADDR(ReplicationBackupJob, CreateSnapShotInStorage), CreateSnapShotInStorage_Stub_True_1);
    stub.set(ADDR(PluginUtils, WriteFile), CreateResourceMock);
    stub.set(ADDR(PluginUtils, IsFileExist), CreateResourceMock);
    EXPECT_EQ(m_nasReplicationBackupJob->PreStartTask(), MP_TRUE);
    stub.reset((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem));
    stub.reset(ADDR(PluginUtils, IsFileExist));
    stub.reset(ADDR(PluginUtils, WriteFile));
    stub.reset(ReplicationBackupJob_InitDeviceInfo);
    stub.reset(ADDR(NasReplicationService, GetPairInfoInProduct));
    stub.reset(ADDR(ReplicationBackupJob, CreateSnapShotInStorage));
    stub.reset(ADDR(PluginUtils, CheckDeviceNetworkConnect));
}

/*
 * 用例名称：CheckPreStartTaskNoInit
 * 前置条件：无
 * check点：PreStartTask执行失败
 */
TEST_F(ReplicationBackupJobTest, CheckPreStartTaskNoInit)
{
    stub.set(ADDR(SecurityService, CheckCertThumbPrint), CheckCertThumbPrint_Stub_True);
    stub.set(ADDR(ReplicationCommonService, UpdateDeviceAvilableIP), UpdateDeviceAvilableIP_Stub_True);
    stub.set((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem), QueryFileSystem_Stub_True);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_False);
    stub.set(ADDR(HetroCommonService, QueryResource), QueryResourceMock);
    stub.set(ADDR(HetroCommonService, CreateResource), CreateResourceMock);
    EXPECT_EQ(m_nasReplicationBackupJob->PreStartTask(), MP_FALSE);
    stub.reset(ADDR(HetroCommonService, CreateResource));
    stub.reset(ADDR(HetroCommonService, QueryResource));
    stub.reset(ADDR(SecurityService, CheckCertThumbPrint));
    stub.reset(ADDR(ReplicationCommonService, UpdateDeviceAvilableIP));
    stub.reset((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem));
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
}

/*
 * 用例名称：CheckPreStartTaskNoInitIsReport
 * 前置条件：无
 * check点：PreStartTask执行失败
 */
TEST_F(ReplicationBackupJobTest, CheckPreStartTaskNoInitIsReport)
{
    stub.set(ADDR(SecurityService, CheckCertThumbPrint), CheckCertThumbPrint_Stub_True);
    stub.set(ADDR(ReplicationCommonService, UpdateDeviceAvilableIP), UpdateDeviceAvilableIP_Stub_True);
    stub.set((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem), QueryFileSystem_Stub_True);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_True);
    stub.set(ADDR(HetroCommonService, QueryResource), QueryResourceMock);
    stub.set(ADDR(HetroCommonService, CreateResource), CreateResourceMock);
    EXPECT_EQ(m_nasReplicationBackupJob->PreStartTask(), MP_FALSE);
    stub.reset(ADDR(HetroCommonService, CreateResource));
    stub.reset(ADDR(HetroCommonService, QueryResource));
    stub.reset(ADDR(SecurityService, CheckCertThumbPrint));
    stub.reset(ADDR(ReplicationCommonService, UpdateDeviceAvilableIP));
    stub.reset((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem));
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
}

/*
 * 用例名称：CheckPreStartTaskNoGetPairInfoInProduct
 * 前置条件：无
 * check点：PreStartTask执行失败
 */
TEST_F(ReplicationBackupJobTest, CheckPreStartTaskNoGetPairInfoInProduct)
{
    typedef bool (*fptr)(ReplicationBackupJob*);

    fptr ReplicationBackupJob_InitDeviceInfo = (fptr)(&ReplicationBackupJob::InitDeviceInfo);
    
    stub.set((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem), QueryFileSystem_Stub_True);
    stub.set(ReplicationBackupJob_InitDeviceInfo, InitDeviceInfo_Stub_True);
    stub.set(ADDR(NasReplicationService, GetPairInfoInProduct), GetPairInfoInProduct_Stub_False);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_False);
    stub.set(ADDR(HetroCommonService, QueryResource), QueryResourceMock);
    stub.set(ADDR(HetroCommonService, CreateResource), CreateResourceMock);
    EXPECT_EQ(m_nasReplicationBackupJob->PreStartTask(), MP_FALSE);
    stub.reset(ADDR(HetroCommonService, CreateResource));
    stub.reset(ADDR(HetroCommonService, QueryResource));
    stub.reset((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem));
    stub.reset(ReplicationBackupJob_InitDeviceInfo);
    stub.reset(ADDR(NasReplicationService, GetPairInfoInProduct));
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
}

/*
 * 用例名称：CheckPreStartTaskNoGetPairInfoInProductIsReport
 * 前置条件：无
 * check点：PreStartTask执行失败
 */
TEST_F(ReplicationBackupJobTest, CheckPreStartTaskNoGetPairInfoInProductIsReport)
{
    typedef bool (*fptr)(ReplicationBackupJob*);

    fptr ReplicationBackupJob_InitDeviceInfo = (fptr)(&ReplicationBackupJob::InitDeviceInfo);
    
    stub.set((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem), QueryFileSystem_Stub_True);
    stub.set(ReplicationBackupJob_InitDeviceInfo, InitDeviceInfo_Stub_True);
    stub.set(ADDR(NasReplicationService, GetPairInfoInProduct), GetPairInfoInProduct_Stub_False);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_True);
    stub.set(ADDR(HetroCommonService, QueryResource), QueryResourceMock);
    stub.set(ADDR(HetroCommonService, CreateResource), CreateResourceMock);
    EXPECT_EQ(m_nasReplicationBackupJob->PreStartTask(), MP_FALSE);
    stub.reset(ADDR(HetroCommonService, CreateResource));
    stub.reset(ADDR(HetroCommonService, QueryResource));
    stub.reset((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem));
    stub.reset(ReplicationBackupJob_InitDeviceInfo);
    stub.reset(ADDR(NasReplicationService, GetPairInfoInProduct));
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
}

/*
 * 用例名称：CheckPreStartTaskNoCreate
 * 前置条件：无
 * check点：PreStartTask执行失败
 */
TEST_F(ReplicationBackupJobTest, CheckPreStartTaskNoCreate)
{
    typedef bool (*fptr)(ReplicationBackupJob*);

    fptr ReplicationBackupJob_InitDeviceInfo = (fptr)(&ReplicationBackupJob::InitDeviceInfo);

    stub.set((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem), QueryFileSystem_Stub_True);
    stub.set(ReplicationBackupJob_InitDeviceInfo, InitDeviceInfo_Stub_True);
    stub.set(ADDR(NasReplicationService, GetPairInfoInProduct), GetPairInfoInProduct_Stub_True);
    stub.set(ADDR(ReplicationBackupJob, CreateSnapShotInStorage), CreateSnapShotInStorage_Stub_False_1);
    stub.set(ADDR(HetroCommonService, QueryResource), QueryResourceMock);
    stub.set(ADDR(HetroCommonService, CreateResource), CreateResourceMock);
    EXPECT_EQ(m_nasReplicationBackupJob->PreStartTask(), MP_FALSE);
    stub.reset(ADDR(HetroCommonService, CreateResource));
    stub.reset(ADDR(HetroCommonService, QueryResource));
    stub.reset((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem));
    stub.reset(ReplicationBackupJob_InitDeviceInfo);
    stub.reset(ADDR(NasReplicationService, GetPairInfoInProduct));
    stub.reset(ADDR(ReplicationBackupJob, CreateSnapShotInStorage));
}

/*
 * 用例名称：CheckPreStartTaskFailed
 * 前置条件：无
 * check点：PreStartTask执行失败
 */
TEST_F(ReplicationBackupJobTest, CheckPreStartTaskFailed)
{
    stub.set(ADDR(HetroCommonService, QueryResource), QueryResourceMock);
    stub.set(ADDR(HetroCommonService, CreateResource), CreateResourceMock);
    stub.set(ADDR(PluginUtils,CheckDeviceNetworkConnect), CheckDeviceNetworkConnect_Stub_False);
    EXPECT_EQ(m_nasReplicationBackupJob->PreStartTask(), MP_FALSE);
    stub.reset(ADDR(HetroCommonService, CreateResource));
    stub.reset(ADDR(HetroCommonService, QueryResource));
    stub.reset(ADDR(PluginUtils, CheckDeviceNetworkConnect));
}

/*
 * 用例名称：CheckInitializeTask
 * 前置条件：无
 * check点：InitializeTask执行成功
 */
TEST_F(ReplicationBackupJobTest, CheckInitializeTask)
{
    stub.set(PluginUtils::CheckDeviceNetworkConnect, CheckDeviceNetworkConnect_Stub_True);
    stub.set(ADDR(SecurityService, CheckCertThumbPrint), CheckCertThumbPrint_Stub_True);
    stub.set(ADDR(ReplicationCommonService, UpdateDeviceAvilableIP), UpdateDeviceAvilableIP_Stub_True);
    stub.set((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem), QueryFileSystem_Stub_True);
    EXPECT_EQ(m_nasReplicationBackupJob->InitializeTask(), MP_SUCCESS);
    stub.reset(PluginUtils::CheckDeviceNetworkConnect);
    stub.reset(ADDR(SecurityService, CheckCertThumbPrint));
    stub.reset(ADDR(ReplicationCommonService, UpdateDeviceAvilableIP));
    stub.reset((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem));
}

/*
 * 用例名称：CheckInitializeTaskFailed
 * 前置条件：无
 * check点：InitializeTask执行失败
 */
TEST_F(ReplicationBackupJobTest, CheckInitializeTaskFailed)
{
    stub.set(ADDR(PluginUtils,CheckDeviceNetworkConnect), CheckDeviceNetworkConnect_Stub_True);
    EXPECT_EQ(m_nasReplicationBackupJob->InitializeTask(), MP_FALSE);
    stub.reset(ADDR(PluginUtils, CheckDeviceNetworkConnect));
}

/*
 * 用例名称：CheckCheckAndCreatePair
 * 前置条件：无
 * check点：CheckAndCreatePair执行成功
 */
TEST_F(ReplicationBackupJobTest, CheckCheckAndCreatePair)
{
    string m_productFSID = "";
    string m_basicFSID = "";
    uint64_t m_qos = 0;
    m_nasReplicationBackupJob->m_nasReplicationServiceObj = NasRepServiceObjOp::NasReplicationService::GetReplicationInstance(
        m_productFSID, m_basicFSID, m_qos);
    m_nasReplicationBackupJob->m_nasReplicationServiceObj->m_remoteDeviceID = "1";
    stub.set(ADDR(NasReplicationService, IsExistPairValid), IsExistPairValid_Stub_False);
    stub.set(ADDR(NasReplicationService, GetPairInfoInProduct), GetPairInfoInProduct_Stub_True);
    stub.set(ADDR(NasReplicationService, GetPairInfoByID), GetPairInfoByID_Stub_True);
    stub.set(ADDR(NasReplicationService, CreateReplicationPair), CreateReplicationPair_Stub_True);
    EXPECT_EQ(m_nasReplicationBackupJob->CheckAndCreatePair(), MP_TRUE);
    stub.reset(ADDR(NasReplicationService, GetPairInfoInProduct));
    stub.reset(ADDR(NasReplicationService, IsExistPairValid));
    stub.reset(ADDR(NasReplicationService, GetPairInfoByID));
    stub.reset(ADDR(NasReplicationService, CreateReplicationPair));
}

/*
 * 用例名称：CheckCheckAndCreatePair
 * 前置条件：无
 * check点：CheckAndCreatePair执行成功
 */
TEST_F(ReplicationBackupJobTest, CheckCheckAndCreatePairIsExist)
{
    stub.set(ADDR(NasReplicationService, IsExistPairValid), IsExistPairValid_Stub_True);
    EXPECT_EQ(m_nasReplicationBackupJob->CheckAndCreatePair(), MP_TRUE);
    stub.reset(ADDR(NasReplicationService, IsExistPairValid));
}

/*
 * 用例名称：CheckCheckAndCreatePair
 * 前置条件：无
 * check点：CheckAndCreatePair执行失败
 */
TEST_F(ReplicationBackupJobTest, CheckCheckAndCreatePairIsExistNoCreate)
{
    string m_productFSID = "";
    string m_basicFSID = "";
    uint64_t m_qos = 0;
    m_nasReplicationBackupJob->m_nasReplicationServiceObj = NasRepServiceObjOp::NasReplicationService::GetReplicationInstance(
        m_productFSID, m_basicFSID, m_qos);
    m_nasReplicationBackupJob->m_nasReplicationServiceObj->m_remoteDeviceID = "1";
    stub.set(ADDR(NasReplicationService, IsExistPairValid), IsExistPairValid_Stub_False);
    stub.set(ADDR(NasReplicationService, GetPairInfoInProduct), GetPairInfoInProduct_Stub_True);
    stub.set(ADDR(NasReplicationService, GetPairInfoByID), GetPairInfoByID_Stub_True);
    stub.set(ADDR(NasReplicationService, CreateReplicationPair), CreateReplicationPair_Stub_False);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_True);
    EXPECT_EQ(m_nasReplicationBackupJob->CheckAndCreatePair(), MP_FALSE);
    stub.reset(ADDR(NasReplicationService, GetPairInfoInProduct));
    stub.reset(ADDR(NasReplicationService, IsExistPairValid));
    stub.reset(ADDR(NasReplicationService, GetPairInfoByID));
    stub.reset(ADDR(NasReplicationService, CreateReplicationPair));
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
}

/*
 * 用例名称：CheckCheckAndCreatePair
 * 前置条件：无
 * check点：CheckAndCreatePair执行成功
 */
TEST_F(ReplicationBackupJobTest, CheckCheckAndCreatePairIsExistNoCreateNoReport)
{
    string m_productFSID = "";
    string m_basicFSID = "";
    uint64_t m_qos = 0;
    m_nasReplicationBackupJob->m_nasReplicationServiceObj = NasRepServiceObjOp::NasReplicationService::GetReplicationInstance(
        m_productFSID, m_basicFSID, m_qos);
    m_nasReplicationBackupJob->m_nasReplicationServiceObj->m_remoteDeviceID = "1";
    stub.set(ADDR(NasReplicationService, IsExistPairValid), IsExistPairValid_Stub_False);
    stub.set(ADDR(NasReplicationService, GetPairInfoInProduct), GetPairInfoInProduct_Stub_True);
    stub.set(ADDR(NasReplicationService, GetPairInfoByID), GetPairInfoByID_Stub_True);
    stub.set(ADDR(NasReplicationService, CreateReplicationPair), CreateReplicationPair_Stub_False);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_False);
    stub.set(ADDR(ControlDevice, GetErrorCode), GetErrorCode_Stub);
    EXPECT_EQ(m_nasReplicationBackupJob->CheckAndCreatePair(), MP_FALSE);
    stub.reset(ADDR(NasReplicationService, GetPairInfoInProduct));
    stub.reset(ADDR(NasReplicationService, IsExistPairValid));
    stub.reset(ADDR(NasReplicationService, GetPairInfoByID));
    stub.reset(ADDR(NasReplicationService, CreateReplicationPair));
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
    stub.reset(ADDR(ControlDevice, GetErrorCode));
}

/*
 * 用例名称：CheckCreateSnapShotInStorage
 * 前置条件：无
 * check点：CreateSnapShotInStorage执行成功
 */
TEST_F(ReplicationBackupJobTest, CheckCreateSnapShotInStorage)
{
    m_nasReplicationBackupJob->m_backupPara->copy.id = {"1"};
    stub.set((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem), QueryFileSystem_Stub_True);
    stub.set(ADDR(DoradoNas, GetESN), GetESN_Stub_Suc);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_False);
    stub.set(ADDR(NasReplicationService, CreateSnapShotInStorage), CreateSnapShotInStorage_Stub_True_2);
    EXPECT_EQ(m_nasReplicationBackupJob->CreateSnapShotInStorage(), MP_TRUE);
    stub.reset((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem));
    stub.reset(ADDR(DoradoNas, GetESN));
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
    stub.reset(ADDR(NasReplicationService, CreateSnapShotInStorage));
}

/*
 * 用例名称：CheckCreateSnapShotInStorageEmpty
 * 前置条件：无
 * check点：CreateSnapShotInStorage执行失败
 */
TEST_F(ReplicationBackupJobTest, CheckCreateSnapShotInStorageEmpty)
{
    stub.set((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem), QueryFileSystem_Stub_True);
    stub.set(ADDR(DoradoNas, GetESN), GetESN_Stub_Suc);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_False);
    EXPECT_EQ(m_nasReplicationBackupJob->CreateSnapShotInStorage(), MP_FALSE);
    stub.reset((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem));
    stub.reset(ADDR(DoradoNas, GetESN));
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
}

/*
 * 用例名称：CheckCreateSnapShotInStorageEmptyIsReport
 * 前置条件：无
 * check点：CreateSnapShotInStorage执行失败
 */
TEST_F(ReplicationBackupJobTest, CheckCreateSnapShotInStorageEmptyIsReport)
{
    stub.set((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem), QueryFileSystem_Stub_True);
    stub.set(ADDR(DoradoNas, GetESN), GetESN_Stub_Suc);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_True);
    EXPECT_EQ(m_nasReplicationBackupJob->CreateSnapShotInStorage(), MP_FALSE);
    stub.reset((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem));
    stub.reset(ADDR(DoradoNas, GetESN));
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
}

/*
 * 用例名称：CheckCreateSnapShotInStorageNoCreateIsReport
 * 前置条件：无
 * check点：CreateSnapShotInStorage执行
 */
TEST_F(ReplicationBackupJobTest, CheckCreateSnapShotInStorageNoCreate)
{
    m_nasReplicationBackupJob->m_backupPara->copy.id = {"1"};
    stub.set((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem), QueryFileSystem_Stub_True);
    stub.set(ADDR(DoradoNas, GetESN), GetESN_Stub_Suc);
    stub.set(ADDR(NasReplicationService, CreateSnapShotInStorage), CreateSnapShotInStorage_Stub_False_2);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_False);
    EXPECT_EQ(m_nasReplicationBackupJob->CreateSnapShotInStorage(), MP_FALSE);
    stub.reset((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem));
    stub.reset(ADDR(DoradoNas, GetESN));
    stub.reset(ADDR(NasReplicationService, CreateSnapShotInStorage));
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
}

/*
 * 用例名称：CheckCreateSnapShotInStorageNoCreateIsReport
 * 前置条件：无
 * check点：CreateSnapShotInStorage执行
 */
TEST_F(ReplicationBackupJobTest, CheckCreateSnapShotInStorageNoCreateIsReport)
{
    m_nasReplicationBackupJob->m_backupPara->copy.id = {"1"};
    stub.set((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem), QueryFileSystem_Stub_True);
    stub.set(ADDR(DoradoNas, GetESN), GetESN_Stub_Suc);
    stub.set(ADDR(NasReplicationService, CreateSnapShotInStorage), CreateSnapShotInStorage_Stub_False_2);
    stub.set(ADDR(ReplicationCommonService, IsReportAgentErrorCode), IsReportAgentErrorCode_Stub_True);
    EXPECT_EQ(m_nasReplicationBackupJob->CreateSnapShotInStorage(), MP_FALSE);
    stub.reset((int(DoradoNas::*)(std::string, DeviceDetails&))ADDR(DoradoNas, QueryFileSystem));
    stub.reset(ADDR(DoradoNas, GetESN));
    stub.reset(ADDR(NasReplicationService, CreateSnapShotInStorage));
    stub.reset(ADDR(ReplicationCommonService, IsReportAgentErrorCode));
}

/*
 * 用例名称：CheckCleanTask
 * 前置条件：无
 * check点：CleanTask执行无异常
 */
TEST_F(ReplicationBackupJobTest, CheckCleanTask)
{
    stub.set(ADDR(NasReplicationService, GetPairInfoInProduct), GetPairInfoInProduct_Stub_True);
    stub.set(ADDR(NasReplicationService, SplitReplicationPair), SplitReplicationPair_Stub_True);
    stub.set(ADDR(NasReplicationService, GetPairInfoByID), GetPairInfoByID_Stub_False);
    EXPECT_NO_THROW(m_nasReplicationBackupJob->CleanTask(AppProtect::JobResult::type::SUCCESS));
    stub.reset(ADDR(NasReplicationService, GetPairInfoInProduct));
    stub.reset(ADDR(NasReplicationService, SplitReplicationPair));
    stub.reset(ADDR(NasReplicationService, GetPairInfoByID));
}

/*
 * 用例名称：CheckCleanTaskNoGetPairInfoInProduct
 * 前置条件：无
 * check点：CleanTask执行无异常
 */
TEST_F(ReplicationBackupJobTest, CheckCleanTaskNoGetPairInfoInProduct)
{
    stub.set(ADDR(NasReplicationService, GetPairInfoInProduct), GetPairInfoInProduct_Stub_False);
    EXPECT_NO_THROW(m_nasReplicationBackupJob->CleanTask(AppProtect::JobResult::type::SUCCESS));
    stub.reset(ADDR(NasReplicationService, GetPairInfoInProduct));
}

/*
 * 用例名称：CheckCleanTaskNoSplit
 * 前置条件：无
 * check点：CleanTask执行无异常
 */
TEST_F(ReplicationBackupJobTest, CheckCleanTaskNoSplit)
{
    stub.set(ADDR(NasReplicationService, GetPairInfoInProduct), GetPairInfoInProduct_Stub_True);
    stub.set(ADDR(NasReplicationService, SplitReplicationPair), SplitReplicationPair_Stub_False);
    EXPECT_NO_THROW(m_nasReplicationBackupJob->CleanTask(AppProtect::JobResult::type::SUCCESS));
    stub.reset(ADDR(NasReplicationService, SplitReplicationPair));
    stub.reset(ADDR(NasReplicationService, GetPairInfoInProduct));
}

/*
 * 用例名称：CheckCleanTaskGetPairInfoByID
 * 前置条件：无
 * check点：CleanTask执行无异常
 */
TEST_F(ReplicationBackupJobTest, CheckCleanTaskGetPairInfoByID)
{
    stub.set(ADDR(NasReplicationService, GetPairInfoInProduct), GetPairInfoInProduct_Stub_True);
    stub.set(ADDR(NasReplicationService, SplitReplicationPair), SplitReplicationPair_Stub_True);
    stub.set(ADDR(NasReplicationService, GetPairInfoByID), GetPairInfoByID_Stub_True);
    EXPECT_NO_THROW(m_nasReplicationBackupJob->CleanTask(AppProtect::JobResult::type::SUCCESS));
    stub.reset(ADDR(NasReplicationService, SplitReplicationPair));
    stub.reset(ADDR(NasReplicationService, GetPairInfoInProduct));
    stub.reset(ADDR(NasReplicationService, GetPairInfoByID));
}

/*
 * 用例名称：CheckCleanTaskGetPairInfoByIDNoSwitch
 * 前置条件：无
 * check点：CleanTask执行无异常
 */
TEST_F(ReplicationBackupJobTest, CheckCleanTaskGetPairInfoByIDNoSwitch)
{
    stub.set(ADDR(NasReplicationService, GetPairInfoInProduct), GetPairInfoInProduct_Stub_True);
    stub.set(ADDR(NasReplicationService, SplitReplicationPair), SplitReplicationPair_Stub_True);
    stub.set(ADDR(NasReplicationService, GetPairInfoByID), GetPairInfoByID_Stub_True);
    stub.set(ADDR(NasReplicationService, SwitchOverPrimaryAndSecondResource), SwitchOverPrimaryAndSecondResource_Stub_False);
    EXPECT_NO_THROW(m_nasReplicationBackupJob->CleanTask(AppProtect::JobResult::type::SUCCESS));
    stub.reset(ADDR(NasReplicationService, SplitReplicationPair));
    stub.reset(ADDR(NasReplicationService, GetPairInfoInProduct));
    stub.reset(ADDR(NasReplicationService, GetPairInfoByID));
    stub.reset(ADDR(NasReplicationService, SwitchOverPrimaryAndSecondResource));
}

/*
 * 用例名称：CheckDeleteBackupSnapshot
 * 前置条件：无
 * check点：DeleteBackupSnapshot执行无异常
 */
TEST_F(ReplicationBackupJobTest, CheckDeleteBackupSnapshot)
{
    m_nasReplicationBackupJob->m_backupPara->copy.id = {"1"};
    stub.set(ADDR(NasReplicationService, DeleteSnapShotInStorage), DeleteSnapShotInStorage_Stub_True);
    EXPECT_NO_THROW(m_nasReplicationBackupJob->DeleteBackupSnapshot(AppProtect::JobResult::type::FAILED));
    stub.reset(ADDR(NasReplicationService, DeleteSnapShotInStorage));
}

/*
 * 用例名称：CheckDeleteBackupSnapshot
 * 前置条件：无
 * check点：DeleteBackupSnapshot执行无异常
 */
TEST_F(ReplicationBackupJobTest, CheckDeleteBackupSnapshotEmpty)
{
    EXPECT_NO_THROW(m_nasReplicationBackupJob->DeleteBackupSnapshot(AppProtect::JobResult::type::FAILED));
}

/*
 * 用例名称：CheckDeleteBackupSnapshot
 * 前置条件：无
 * check点：DeleteBackupSnapshot执行无异常
 */
TEST_F(ReplicationBackupJobTest, CheckDeleteBackupSnapshotNoDelete)
{
    m_nasReplicationBackupJob->m_backupPara->copy.id = {"1"};
    stub.set(ADDR(NasReplicationService, DeleteSnapShotInStorage), DeleteSnapShotInStorage_Stub_False);
    EXPECT_NO_THROW(m_nasReplicationBackupJob->DeleteBackupSnapshot(AppProtect::JobResult::type::FAILED));
    stub.reset(ADDR(NasReplicationService, DeleteSnapShotInStorage));
}

/*
 * 用例名称：CheckDeleteBackupSnapshot
 * 前置条件：无
 * check点：DeleteBackupSnapshot执行无异常
 */
TEST_F(ReplicationBackupJobTest, CheckDeleteBackupSnapshotSuc)
{
    m_nasReplicationBackupJob->m_backupPara->copy.id = {"1"};
    stub.set(ADDR(NasReplicationService, DeleteSnapShotInStorage), DeleteSnapShotInStorage_Stub_True);
    EXPECT_NO_THROW(m_nasReplicationBackupJob->DeleteBackupSnapshot(AppProtect::JobResult::type::SUCCESS));
    stub.reset(ADDR(NasReplicationService, DeleteSnapShotInStorage));
}